﻿namespace Sidvall.AuthorizationManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class UserConfiguration : global::Sidvall.AuthorizationManager.UI.Entities.Core.BusinessBase, global::Sidvall.AuthorizationManager.Data.IUserConfiguration
    {
        #region Business Members

        #region Name

        private string _Name = string.Empty;
        partial void OnBeforeNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Name);
                OnBeforeNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                OnBeforeNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Name", eventData.Value, true, true, true);
                    OnAfterNamePropertyChanged();
                }
            }
        }

        #endregion
        #region ShowNewsAtStartup

        private bool _ShowNewsAtStartup = false;
        partial void OnBeforeShowNewsAtStartupPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeShowNewsAtStartupPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterShowNewsAtStartupPropertyChanged();
        public bool ShowNewsAtStartup
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_ShowNewsAtStartup);
                OnBeforeShowNewsAtStartupPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _ShowNewsAtStartup);
                OnBeforeShowNewsAtStartupPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ShowNewsAtStartup", eventData.Value, true, true, true);
                    OnAfterShowNewsAtStartupPropertyChanged();
                }
            }
        }

        #endregion
        #region StartPageId

        private global::Sidvall.AuthorizationManager.Data.PageType _StartPageId = global::Sidvall.AuthorizationManager.Data.PageType.Dashboard;
        partial void OnBeforeStartPageIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.PageType> eventData);
        partial void OnBeforeStartPageIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.PageType> eventData);
        partial void OnAfterStartPageIdPropertyChanged();
        public global::Sidvall.AuthorizationManager.Data.PageType StartPageId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.PageType> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.AuthorizationManager.Data.PageType>(_StartPageId);
                OnBeforeStartPageIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.PageType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.PageType>(value, _StartPageId);
                OnBeforeStartPageIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("StartPageId", eventData.Value, true, true, true);
                    OnAfterStartPageIdPropertyChanged();
                }
            }
        }

        #endregion
        #region STSAddress

        private string _STSAddress = string.Empty;
        partial void OnBeforeSTSAddressPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeSTSAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSAddressPropertyChanged();
        public string STSAddress
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_STSAddress);
                OnBeforeSTSAddressPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSAddress);
                OnBeforeSTSAddressPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("STSAddress", eventData.Value, true, true, true);
                    OnAfterSTSAddressPropertyChanged();
                }
            }
        }

        #endregion
        #region STSClientId

        private string _STSClientId = string.Empty;
        partial void OnBeforeSTSClientIdPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeSTSClientIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSClientIdPropertyChanged();
        public string STSClientId
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_STSClientId);
                OnBeforeSTSClientIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSClientId);
                OnBeforeSTSClientIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("STSClientId", eventData.Value, true, true, true);
                    OnAfterSTSClientIdPropertyChanged();
                }
            }
        }

        #endregion
        #region STSClientSecret

        private string _STSClientSecret = string.Empty;
        partial void OnBeforeSTSClientSecretPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeSTSClientSecretPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSClientSecretPropertyChanged();
        public string STSClientSecret
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_STSClientSecret);
                OnBeforeSTSClientSecretPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSClientSecret);
                OnBeforeSTSClientSecretPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("STSClientSecret", eventData.Value, true, true, true);
                    OnAfterSTSClientSecretPropertyChanged();
                }
            }
        }

        #endregion
        #region UserConfigurationId

        private System.Nullable<int> _UserConfigurationId = null;
        partial void OnBeforeUserConfigurationIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData);
        partial void OnBeforeUserConfigurationIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterUserConfigurationIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<int> UserConfigurationId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<int>>(_UserConfigurationId);
                OnBeforeUserConfigurationIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _UserConfigurationId);
                OnBeforeUserConfigurationIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UserConfigurationId", eventData.Value, true, true, true);
                    OnAfterUserConfigurationIdPropertyChanged();
                }
            }
        }

        #endregion
        #region ServerConnections

        private ServerConnectionCollection _ServerConnections;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public ServerConnectionCollection ServerConnections
        {
            get
            {
                return _ServerConnections;
            }
            internal set
            {
                LoadInstanceField("ServerConnections", value, true, false, false);
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadServerConnections

        public void LoadServerConnections(ServerConnectionCollection value)
        {
            LoadInstanceField("ServerConnections", value, true, true, false);
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public UserConfiguration Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public UserConfiguration Copy()
        {
            return Copy(null);
        }
        public UserConfiguration Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new UserConfiguration();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IUserConfiguration item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IUserConfiguration item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(UserConfiguration destination, global::Sidvall.AuthorizationManager.Data.IUserConfiguration source, Sidvall.Data.CopySettings copySettings);
        private void Import(UserConfiguration destination, global::Sidvall.AuthorizationManager.Data.IUserConfiguration source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(UserConfiguration destination, UserConfiguration source, Sidvall.Data.CopySettings copySettings);
        private void Import(UserConfiguration destination, UserConfiguration source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.AuthorizationManager.Data.IUserConfiguration, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.UI.SystemContextConfig.Current.EntityFacade.UserConfigurationManager.Initialize(this, settings);
        }

        #endregion
        
        #region IUserConfiguration Members

        string global::Sidvall.AuthorizationManager.Data.IUserConfiguration.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IUserConfiguration.ShowNewsAtStartup
        {
            get
            {
                return this._ShowNewsAtStartup;
            }
            set
            {
                this._ShowNewsAtStartup = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.PageType global::Sidvall.AuthorizationManager.Data.IUserConfiguration.StartPageId
        {
            get
            {
                return this._StartPageId;
            }
            set
            {
                this._StartPageId = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IUserConfiguration.STSAddress
        {
            get
            {
                return this._STSAddress;
            }
            set
            {
                this._STSAddress = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IUserConfiguration.STSClientId
        {
            get
            {
                return this._STSClientId;
            }
            set
            {
                this._STSClientId = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IUserConfiguration.STSClientSecret
        {
            get
            {
                return this._STSClientSecret;
            }
            set
            {
                this._STSClientSecret = value;
            }
        }
        System.Nullable<int> global::Sidvall.AuthorizationManager.Data.IUserConfiguration.UserConfigurationId
        {
            get
            {
                return this._UserConfigurationId;
            }
            set
            {
                this._UserConfigurationId = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IServerConnection> global::Sidvall.AuthorizationManager.Data.IUserConfiguration.ServerConnections
        {
            get
            {
                return this._ServerConnections;
            }
        }
        void global::Sidvall.AuthorizationManager.Data.IUserConfiguration.SetServerConnections(Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IServerConnection> items)
        {
            UpdateChildProperty(this._ServerConnections, items);
            this._ServerConnections = items as ServerConnectionCollection;
        }

        #endregion

        #endregion
        #region Constructors

        public UserConfiguration()
        {
        }

        public UserConfiguration(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}